package com.cwx.mychat.mappers;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cwx.mychat.entity.po.AIConfig;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 作者： cwx
 * 时间： 2025/5/26 19:21
 * 版本： 1.0
 * 注释：
 */
@Mapper
public interface AIConfigMapper extends BaseMapper<AIConfig> {


    /**
     * 靠用户Id查询AI信息
     * @param userId
     * @return
     */
    @Select("select * from ai_config where user_id = #{userId} and enable = 1")
    @Results({
            @Result(
                    column = "model_id",
                    property = "model",
                    javaType = List.class,
                    many = @Many(
                            select = "com.cwx.mychat.mappers.AIConfigMapper.selectListByModelId"
                    )
            ),

    })
    List<AIConfig> selectListByUserIdEnable(String userId);

    @Select("SELECT ai_model_id, model_name, enable FROM ai_model WHERE ai_id = #{id}")
    @ConstructorArgs({
            @Arg(column = "ai_model_id", javaType = Integer.class),
            @Arg(column = "model_name", javaType = String.class),
            @Arg(column = "enable", javaType = Integer.class)
    })
    List<AIConfig.Model> selectListByModelId(String id);

    /**
     * 批量将enable改为0
     * @param aiListIds
     */
    @Update("update ai_config set enable = 0 where id in (#{aiListIds})")
    void updateBatchEnableById(List<Integer> aiListIds);
}
